package com.gxa.controller;

import com.gxa.common.LayR;
import com.gxa.common.R;
import com.gxa.param.AddCusatis;
import com.gxa.param.MyTableParam;
import com.gxa.pojo.Customer;
import com.gxa.pojo.Satisfaction;
import com.gxa.pojo.Type;
import com.gxa.pojo.Value;
import com.gxa.service.customerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/customer")
public class CustomerController {
    @Autowired
    private customerService customerService;
    /**
     * 客户价值列表数据
     * @return
     */
    @GetMapping("/value/list")
    public String valuelist(){
        return "customer/cust-value-list";
    }


    @PostMapping("/valuelist/data")
    @ResponseBody
    public LayR valuelistData(MyTableParam param){
        return customerService.list(param);
    }


    /**
     * 客户满意度列表数据
     * @return
     */
    @GetMapping("/satisfaction/list")
    public String satisfactionlist(){
        return "customer/cust-satisfatory-list";
    }

    @PostMapping("/satislist/data")
    @ResponseBody
    public LayR satisfactionlistData(MyTableParam param){
        return customerService.satislist(param);
    }


    /**
     * 客户历史订单列表数据
     * @return
     */
    @GetMapping("/order/list")
    public String orderlist(Integer id, Model model, HttpSession session){
        session.setAttribute("customerId",id);
        model.addAttribute("customerId",id);
        System.out.println(id);
        return "customer/cust-order-list";
    }

    @PostMapping("/orderlist/data")
    @ResponseBody
    public LayR orderlistData(HttpSession session, MyTableParam param){
        Integer customerId= (Integer) session.getAttribute("customerId");
        return customerService.orderlist(customerId,param);
    }








    /**
     * 客户类别列表数据
     * @return
     */
    @PostMapping("/typelist/data")
    @ResponseBody
    public LayR typelistData(){
        return customerService.typelist();
    }

    /**
     * 客户满意度添加页面
     * @return
     */
    @GetMapping("/value/add/page")
    public String satisfactionadd(){
        return "customer/cust-satisfatory-add";
    }

    @PostMapping("/add/do")
    @ResponseBody
    public R add(AddCusatis addCusatis,HttpSession session){
        System.out.println(addCusatis);
        return customerService.add(addCusatis,session);
    }



    /**
     *  客户满意度修改页面
     * @return
     */
    @GetMapping("/edit/page")
    public String satisfactionedit(Integer id, Model model,HttpSession session){
        session.setAttribute("customerId",id);
        model.addAttribute("customerId", id);
        return "customer/cust-satisfatory-edit";
    }

    @PostMapping("/edit/do")
    @ResponseBody
    public R edit(AddCusatis addCusatis,  HttpSession session){
        Integer customerId = (Integer) session.getAttribute("customerId");
        System.out.println("ID+"+customerId);
        System.out.println(addCusatis);
        addCusatis.setCustomerId(customerId);
        return customerService.edit(addCusatis,session);
    }


    @PostMapping("/deleteOne")
    @ResponseBody
    public R deleteOne(Integer customerid,Integer satisId){
        return customerService.deleteOne(customerid,satisId);

    }
/**
 * 客户详情页面
 * @return
 */
    @GetMapping("/see/page")
    public String seePage(Integer id, Model model,HttpSession session){
        session.setAttribute("customerId",id);
        System.out.println(id);
        model.addAttribute("customerId", id);
        System.out.println(id);
        return "customer/cust-satisfatory-see";
    }
    /**
     * 详情
     * @param
     * @return
     */
    @PostMapping("/detail")
    @ResponseBody
    public R detail(HttpSession session){
        return customerService.findfromByID((Integer) session.getAttribute("customerId"));
    }





//    顾客部分
@GetMapping("/resource/list/page")
public String resource(){
    return "customer/customer-list";
}




    @PostMapping("/list/data")
    @ResponseBody
    public LayR list(MyTableParam param){

        return customerService.list(param);
    }



    @PostMapping("/deleteCuOne")
    @ResponseBody
    public R deleteOne(Integer id){

        return customerService.deleteCuOne(id);
}

    @PostMapping("/delete")
    @ResponseBody
    public R delete(@RequestParam("ids[]") String[] ids){
        return customerService.deleteAll(ids);
    }

    @GetMapping("/add/page")
    public String addPage(){
        return "customer/customer-add";
    }

    @PostMapping("/addCu/do")
    @ResponseBody
    public R add(Customer customer, HttpSession session){

        return customerService.addCu(customer,session);

    }

    @GetMapping("/Cuedit/page")
    public String editPage(Integer id, Model model, HttpSession session){
        session.setAttribute("customerId",id);
        model.addAttribute("id", id);
        return "customer/customer-edit";
    }

    @GetMapping("/give/page")
    public String givePage(Integer id, Model model){
        model.addAttribute("giveId", id);
        return "customer/customer-give";
    }


    @PostMapping("/Cudetail")
    @ResponseBody
    public R detail(Integer id){
        return customerService.findCuById(id);
    }

    @PostMapping("/Cuedit/do")
    @ResponseBody
    public R edit(Customer customer,HttpSession session){

        return customerService.editCu(customer,session);

    }
    @PostMapping("/give/do")
    @ResponseBody
    public R give(Customer customer,HttpSession session){

        return customerService.edit1(customer,session);

    }
}
